//
//  ZYCLoginRoleViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/19.
//

#import "ZYCLoginRoleViewController.h"
#import "ZYCLoginRoleView.h"
#import "ZYCMainViewController.h"

@interface ZYCLoginRoleViewController ()<UINavigationControllerDelegate,ZYCLoginRoleViewDelegate>

@property (nonatomic, strong) ZYCLoginRoleView *loginRoleView;
@end

@implementation ZYCLoginRoleViewController
#pragma mark - 生命周期函数
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.loginRoleView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
}


#pragma mark - UINavigationControllerDelegate
-(void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:[viewController isKindOfClass:[self class]] animated:YES];
}



#pragma mark - getters
- (ZYCLoginRoleView *)loginRoleView {
    if (!_loginRoleView) {
        _loginRoleView = [[ZYCLoginRoleView alloc] initWithFrame:self.view.bounds];
        _loginRoleView.delegate = self;
    }
    return _loginRoleView;
}

#pragma mark - ZYCLoginRoleViewDelegate

- (void)loginRoleViewDidBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)loginRoleViewDidRoleComfirm:(ZYCLoginRoleType)roleType{
    
    [[NSUserDefaults standardUserDefaults] setInteger:roleType forKey:@"kUserRoleType"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    ZYCMainViewController *mainVc = [[ZYCMainViewController alloc] init];
    mainVc.roleType = roleType;
    [UIApplication sharedApplication].keyWindow.rootViewController = mainVc;
    [[UIApplication sharedApplication].keyWindow makeKeyAndVisible];
    
}


- (void)dealloc{
    self.navigationController.delegate = nil;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
